// 抽离可公用的工具函数等用于系统管理页面逻辑
import { computed } from "vue";
import { useDark } from "@pureadmin/utils";

export function usePublicHooks() {
  const { isDark } = useDark();

  const switchStyle = computed(() => {
    return {
      "--el-switch-on-color": "#6abe39",
      "--el-switch-off-color": "#e84749"
    };
  });

  const enableStyle = computed(() => {
    return (status: string) => {
      return {
        0: { color: "#f46b6c", text: "停用", style: "danger" },
        1: { color: "#448ef7", text: "启用", style: "success" }
      }[status];
    };
  });
  const flowStatusMap = {
    running: { color: "#448ef7", text: "审批中", style: "primary" }, // 运行中
    completed: { color: "#00b32a", text: "已完成", style: "success" }, // 完成
    terminated: { color: "#f46b6c", text: "已撤销", style: "danger" }, // 撤销
    rejected: { color: "#f46b6c", text: "已拒绝", style: "danger" }, // 已拒绝
    scheduled_rejected: {
      color: "#f46b6c",
      text: "调度已拒绝",
      style: "danger"
    } // 调度已拒绝
  };
  const driverStatusMap = {
    0: { color: "#333333", text: "无", style: "info" },
    1: { color: "#00b32a", text: "空闲", style: "success" },
    2: { color: "#448ef7", text: "出车", style: "primary" }
  };
  const vehicleStatusMap = {
    0: { color: "#333333", text: "禁用", style: "info" },
    1: { color: "#00b32a", text: "正常", style: "success" },
    2: { color: "#448ef7", text: "故障", style: "danger" }
  };
  // 收费类型1-类区域2二类区域3三类区域
  /** 收费类型（AREA_TYPE_1:一类区域, AREA_TYPE_2:二类区域, AREA_TYPE_3:三类区域, CUSTOM:自定义） */
  const parkadeChargeTypeMap = [
    { color: "#f46b6c", text: "一类区域", style: "info", value: "AREA_TYPE_1" },
    { color: "#f46b6c", text: "二类区域", style: "info", value: "AREA_TYPE_2" },
    { color: "#f46b6c", text: "三类区域", style: "info", value: "AREA_TYPE_3" },
    { color: "#f46b6c", text: "其他", style: "info", value: "CUSTOM" }
  ];
  // 停车场类型 0地上1地下2立体3路侧
  /** 停车场类型（GROUND:地上, UNDERGROUND:地下, MULTI_LEVEL:立体, ROADSIDE:路侧） */
  const parkadeTypeMap = [
    { color: "#333333", text: "地上", style: "warning", value: "GROUND" },
    { color: "#448ef7", text: "地下", style: "primary", value: "UNDERGROUND" },
    { color: "#00b32a", text: "立体", style: "success", value: "MULTI_LEVEL" },
    { color: "#448ef7", text: "路侧", style: "info", value: "ROADSIDE" }
  ];
  // 周边类型 1餐饮2景点3加油站4维修
  const peripheryTypeMap = [
    { value: "DINING", color: "#333333", text: "餐饮", style: "warning" },
    { value: "ATTRACTION", color: "#448ef7", text: "景点", style: "primary" },
    // { value: "AIR", color: "#00b32a", text: "加油站", style: "success" },
    { value: "SERVICE", color: "#448ef7", text: "服务", style: "info" }
  ];
  const flowStatusStyle = computed(() => {
    return (status: string) => {
      return flowStatusMap[status];
    };
  });
  const parkadeChargeTypeStyle = computed(() => {
    return (status: string) => {
      return parkadeChargeTypeMap.find(item => item.value == status) || {};
    };
  });
  const peripheryTypeStyle = computed(() => {
    return (status: string) => {
      return peripheryTypeMap.find(item => item.value == status);
    };
  });
  const driverStatusStyle = computed(() => {
    return (status: number) => {
      return driverStatusMap[status];
    };
  });
  const vehicleStatusStyle = computed(() => {
    return (status: number) => {
      return vehicleStatusMap[status];
    };
  });
  const parkadeTypeStyle = computed(() => {
    return (status: string) => {
      return parkadeTypeMap.find(item => item.value == status);
    };
  });
  const sexOptions = [
    {
      value: 0,
      label: "未知"
    },
    {
      value: 1,
      label: "男"
    },
    {
      value: 2,
      label: "女"
    }
  ];
  const specialWorksStatusOptions = [
    {
      value: "1",
      label: "空闲"
    },
    {
      value: "2",
      label: "出车"
    }
  ];
  const tagStyle = computed(() => {
    return (status: number) => {
      return status === 1
        ? {
            "--el-tag-text-color": isDark.value ? "#6abe39" : "#389e0d",
            "--el-tag-bg-color": isDark.value ? "#172412" : "#f6ffed",
            "--el-tag-border-color": isDark.value ? "#274a17" : "#b7eb8f"
          }
        : {
            "--el-tag-text-color": isDark.value ? "#e84749" : "#cf1322",
            "--el-tag-bg-color": isDark.value ? "#2b1316" : "#fff1f0",
            "--el-tag-border-color": isDark.value ? "#58191c" : "#ffa39e"
          };
    };
  });

  return {
    /** 当前网页是否为`dark`模式 */
    isDark,
    /** 表现更鲜明的`el-switch`组件  */
    switchStyle,
    enableStyle,
    /** 表现更鲜明的`el-tag`组件  */
    tagStyle,
    /** 流程状态图标 */
    flowStatusMap,
    /** 流程状态样式 */
    flowStatusStyle,
    /** 收费类型 */
    parkadeChargeTypeStyle,
    parkadeChargeTypeMap,
    /** 调度状态样式 */
    parkadeTypeStyle,
    /** 停车场类型  */
    parkadeTypeMap,
    peripheryTypeStyle,
    peripheryTypeMap,
    /** 司机状态样式 */
    driverStatusStyle,
    /** 司机状态图标 */
    driverStatusMap,
    /** 车辆状态样式 */
    vehicleStatusStyle,
    /** 车辆状态图标 */
    vehicleStatusMap,
    /** 性别选项 */
    sexOptions,
    /** 特勤状态选项 */
    specialWorksStatusOptions
  };
}
